package com.js.basehttp.interceptor;

// Created by JS on 2020/11/20.

import android.text.TextUtils;

import androidx.annotation.NonNull;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class TokenHeaderInterceptor implements Interceptor {

    private String token;

    public TokenHeaderInterceptor(String token) {
        this.token = token;
    }
    @NonNull
    @Override
    public Response intercept(@NonNull Chain chain) throws IOException {
        if (token == null) {
            Request originalRequest = chain.request();
            return chain.proceed(originalRequest);
        }else {
            Request originalRequest = chain.request();
            Request updateRequest = originalRequest.newBuilder().header("TOKEN", token).build();
            return chain.proceed(updateRequest);
        }
    }
}
